//
//  UploadFileList.m
//  MagicCardDemo
//
//  Created by 向恒 on 16/9/16.
//  Copyright © 2016年 向恒. All rights reserved.
//

#import "UploadFileList.h"

@implementation UploadFileList

-(id)init
{
    return self;
}

-(void) Add:(NSString*) filename
{
    
    //需要了解一下NSUserDefaults的使用场景和限制
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    //先读取
    
    NSArray* uploadlist = [defaults objectForKey:@"upload_file_list"];
    [defaults removeObjectForKey:@"upload_file_list"];
    [defaults synchronize];  //做了修改之后需要同步
    NSMutableArray* uploadlist_save = [uploadlist mutableCopy];
    if(uploadlist == nil)
    {
        uploadlist_save = [[NSMutableArray alloc]init];
    }
    
    [uploadlist_save addObject:filename];
    [defaults setObject:uploadlist_save forKey:@"upload_file_list"];
    [defaults synchronize];
    NSMutableArray* test = [defaults objectForKey:@"upload_file_list"];
    NSLog(@"%@",test);

}

-(NSString*) Get
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    //先读取
    
    NSArray* uploadlist = [defaults objectForKey:@"upload_file_list"];
    [defaults removeObjectForKey:@"upload_file_list"];
   [defaults synchronize];
    NSMutableArray* uploadlist_save = [uploadlist mutableCopy];

    
    if([uploadlist count] > 0)
    {
        NSString* str = [uploadlist objectAtIndex:0];
        [uploadlist_save removeObjectAtIndex:0];
        [defaults setObject:uploadlist_save forKey:@"upload_file_list"];
        [defaults synchronize];
        NSMutableArray* test = [defaults objectForKey:@"upload_file_list"];
        NSLog(@"%@",test);
        return str;
    }
    
    return  nil;
}

@end
